import { createCallback } from "../utils/tools";

export default (
  /** arguments */
  target,
  targetName,
  descriptor
) => {
  // console.log(target, targetName, descriptor);
  const fn = descriptor.value;

  descriptor.value = function (options = {}) {
    const ctx = this;

    const {
      errorMsg = "error",
      prop = "prop",
      trigger = "blur",
      required = true,
    } = options;

    const validator = createCallback({
      required,
      prop,
      trigger,
      validator: fn.call(ctx, errorMsg),
    });

    return validator;
  };
};
